Cpp . NET: “a->Methodname ” vs “a.MethodName”?

If you have a pointer to an object, you use: MyClass *a = new MyClass(); a->MethodName() On the other hand, if you have an actual object, you use dotted notation: MyClass a; a.MethodName().

If you have a pointer to an object, you use: MyClass *a = new MyClass(); a->MethodName(); On the other hand, if you have an actual object, you use dotted notation: MyClass a; a.MethodName().

It would be worth mentioning the usage for C++/CLI "handles" also, because the question asks about this specifically. – Greg Hewgill Nov 3 '09 at 18:02.

To clarify the previous answers slightly, the caret character ^ in VC++ can be thought of as a * for most intents and purposes. It is a 'handle' to a class, and means something slightly different, but similar. See this short Googled explanation: blogs.msdn.com/branbray/archive/2003/11/... So, in your example there, if you initialize your connection like: System::Data::Odbc::OdbcConnection connect; //You should be able to do this: connect.Open(); Conversely, if you do this: System::Data::Odbc::OdbcConnection^ connect1 = gcnew System::Data::Odbc::OdbcConnection(); connect1.Open(); // should be an error connect1->Open(); //correct.

There's also a good discussion on the caret right here on Stack Overflow: stackoverflow. Com/questions/202463/… – Rooke Nov 3 '09 at 18:43.

The short answer: C++ allows you to manage your own memory. As such, you can create and manipulate memory, through usage of pointers (essentially integer variables containing memory addresses, rather than a value). A.Method() means a is an instance of a class, from which you call Method.

A->Method() means a is a pointer to an instance of a class, from which you call Method.

When you use syntax like a->member, you are using a pointer to a structure or object. When you use syntax like a. Member, you are using the structure or object and not a pointer to the structure or object.

I did a quick google for you and THIS looks fairly quick and decent explanation.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions